# cmake 要求的最小版本
cmake_minimum_required(VERSION 3.16.3)

message("主机信息: ${CMAKE_HOST_SYSTEM_NAME}")
message("用户名: $ENV{USER}")
message("构建文件目录: ${CMAKE_BINARY_DIR}")
# 设置项目名称 设置版本号
project(socketPro VERSION 0.1 LANGUAGES CXX)

# 设置 c++ 的语言标准 C++14
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
#set(CMAKE_CXX_STANDARD_REQUIRED True)

set(TARGET socketPro)

add_compile_definitions(TARGET_NAME="${TARGET}")
find_package(CUDA QUIET)





add_executable(${TARGET} main.cpp Server.h Server.cpp)


if (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
    find_package(OpenCV)
    find_package(CUDA REQUIRED)
    set(CMAKE_LIBRARY_PATH /data/easier/dynamicLib)
    set(Qt5_DIR "/data/easier/Qt-5.15.5/lib/cmake/Qt5")
    set(CMAKE_PREFIX_PATH /usr/local/Qt-5.15.5)
    set(CURL_DIR /usr/local/Cellar/curl/7.84.0)
    find_package(Threads)
    list(APPEND libs ${CMAKE_THREAD_LIBS_INIT})
    find_package(ZLIB)
    include_directories(${ZLIB_INCLUDE_DIRS})
    list(APPEND libs ${ZLIB_LIBRARIES})
    list(APPEND libs dl)

    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)

    if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Network LinguistTools REQUIRED COMPONENTS Widgets OpenGLWidgets)
    else ()
        find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Network LinguistTools REQUIRED COMPONENTS Widgets PdfWidgets Pdf WebEngineWidgets)
    endif ()

    find_path(ONNX_RUNTIME_SESSION_INCLUDE_DIRS onnxruntime_cxx_api.h
            HINTS /data/easier/onnxruntime-linux-x64-gpu-1.15.0/include/)
    find_path(ONNX_RUNTIME_PROVIDERS_INCLUDE_DIRS cpu_provider_factory.h
            HINTS /data/easier/onnxruntime-linux-x64-gpu-1.15.0/include/)
    find_library(ONNX_RUNTIME_LIB onnxruntime HINTS /data/easier/onnxruntime-linux-x64-gpu-1.15.0/lib)


    # 设置 Python 解释器路径（替换为你的实际路径）
    set(Python_EXECUTABLE "/data/easier/media/bin/python")
    # 查找 Python 组件（包含头文件和库）
    find_package(Python COMPONENTS Interpreter Development REQUIRED)

    # 打印验证路径
    message(STATUS "Python路径: ${Python_EXECUTABLE}")
    message(STATUS "头文件路径: ${Python_INCLUDE_DIRS}")
    message(STATUS "库路径: ${Python_LIBRARIES}")


    target_include_directories(${TARGET} PRIVATE ${Python_INCLUDE_DIRS})
    target_link_libraries(${TARGET} PRIVATE
            ${ONNX_RUNTIME_LIB}
            ${Python_LIBRARIES}
            Qt${QT_VERSION_MAJOR}::Widgets
            Qt${QT_VERSION_MAJOR}::Network
            )


    file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/*.[ch]pp)
    list(REMOVE_ITEM sources
            ${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/CMakeFiles/3.17.5/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/CMakeFiles/3.26.4/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/cmake-build-debug/CMakeFiles/3.28.1/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles/3.16.3/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles/3.26.3/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles/3.26.0/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles/3.24.0/CompilerIdCXX/CMakeCXXCompilerId.cpp
            ${CMAKE_CURRENT_SOURCE_DIR}/CMakeFiles/3.27.1/CompilerIdCXX/CMakeCXXCompilerId.cpp
            )
else()
    message("这里")

    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)

    if (${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Network LinguistTools REQUIRED COMPONENTS Widgets OpenGLWidgets)
    else ()
        find_package(Qt${QT_VERSION_MAJOR} COMPONENTS REQUIRED Network LinguistTools REQUIRED COMPONENTS Widgets PdfWidgets Pdf WebEngineWidgets)
    endif ()


    #    target_include_directories(${TARGET} PRIVATE /opt/anaconda3/envs/paddle/include/python3.9)
    #    find_library(PYTHON_LIB python3.9 PATHS /opt/anaconda3/envs/paddle/lib)
    target_include_directories(${TARGET} PRIVATE /opt/anaconda3/envs/NewCall/include/python3.8)
    find_library(PYTHON_LIB python3.8 PATHS /opt/anaconda3/envs/NewCall/lib)
    target_link_libraries(${TARGET}
            ${PYTHON_LIB}
            Qt${QT_VERSION_MAJOR}::Widgets
            Qt${QT_VERSION_MAJOR}::Network
            )
endif()
